/**
 * Copyright (C) 2012 Oleg Anastassov <o.anastasov@gmail.com>
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package kz.kstu.ent.util;

/**
 * @author Oleg Anastassov
 */
public final class StringUtil {

    public static final String EMPTY_STRING = "";
    public static final String SPACE = " ";
    public static final String DOT = ".";
    public static final String SEMICOLON = ";";

    private static final String GETTER_PREFIX = "get";

    private StringUtil() {
    }

    public static boolean isIntegerNumber(String number) {
        if (number == null) {
            return false;
        }

        for (char ch : number.toCharArray()) {
            if (!Character.isDigit(ch)) {
                return false;
            }
        }
        return true;
    }

    public static boolean isEmptyOrNullString(String value) {
        return value == null || value.length() == 0;
    }

    public static String concatenate(String... strings) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < strings.length; i++) {
            sb.append(strings[i]);
            if (i != (strings.length - 1)) {
                sb.append(" ");
            }
        }
        return sb.toString();
    }

    public static String byteArrayToHexString(byte[] data) {
        StringBuilder buffer = new StringBuilder();
        for (byte element : data) {
            buffer.append(String.format("%02X", element));
            buffer.append(SPACE);
        }
        return buffer.toString();
    }

    public static String getGetterByProperty(String property) {
        return GETTER_PREFIX + property.substring(0, 1).toUpperCase() + property.substring(1);
    }
}
